package com.example.springbootjavafx.scopes;

import com.example.springbootjavafx.domain.User;
import de.saxsys.mvvmfx.Scope;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyStringWrapper;
import javafx.beans.property.SimpleObjectProperty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.stereotype.Component;


@Component
public class UserDetailScope implements Scope {

	private final ObjectProperty<User> selectedUser = new SimpleObjectProperty<>(this, "selectedUser");

	@Getter
	@Setter
	private ReadOnlyStringWrapper idProperty = new ReadOnlyStringWrapper(this, "idProperty");
	@Getter
	@Setter
	private ReadOnlyStringWrapper nameProperty = new ReadOnlyStringWrapper(this, "nameProperty");
	@Getter
	@Setter
	private ReadOnlyStringWrapper addressProperty = new ReadOnlyStringWrapper(this, "addressProperty");


	public ObjectProperty<User> selectedUserProperty() {
		return this.selectedUser;
	}

	public final User getSelectedUser() {
		return this.selectedUserProperty().get();
	}

	public final void setSelectedUser(final User selectedUser) {
		this.selectedUserProperty().set(selectedUser);
		this.idProperty.set(selectedUser.getId());
		this.nameProperty.set(selectedUser.getName());
		this.addressProperty.set(selectedUser.getAddress());
	}

	public void clear() {
		this.selectedUser.set(null);
		this.idProperty.set("");
		this.nameProperty.set("");
		this.addressProperty.set("");
	}



}
